<?php
/**
 * Created by PhpStorm.
 * User: ybjaa
 * Date: 2017/5/4
 * Time: 10:14
 */

namespace App\Business\Menu;

use App\Business\Model\Menu;
use App\Models\menus_manage;
use App\Units;

class GetChildrenMenus extends MenusBase
{

    public $parentID;



    protected function Handle()
    {
        return $this->GetChildrenMenus();
    }


    protected function GetChildrenMenus()
    {

        $menus= menus_manage::all();


        if($menus==null || count($menus)<=0) return null;

        //转化为业务模型对象
        $menus=Units::ArrayToObject($menus->toArray(),Menu::class);

        //获取顶层菜单
        $topMenus=array_filter($menus,function($m){
           return $m->parentID===$this->parentID;
        });

        //排序
        $topMenus=$this->menuSort($topMenus);

        $this->recursion(array_values($topMenus),$menus);

        return array_values($topMenus);



    }


    public function GetBusinessName()
    {
        return "获得子菜单";
    }








}